
import java.awt.Dialog;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author RaoF
 */
public class TransferBalance extends javax.swing.JPanel {

    private ATM atm;
    private JFrame current;

    public TransferBalance(ATM back, JFrame curr) {
        atm = back;
        current = curr;
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jSpinner1 = new javax.swing.JSpinner();
        ok = new javax.swing.JButton();
        cancel = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setLayout(new java.awt.BorderLayout());

        jLabel2.setText("Accnt No.");
        jPanel1.add(jLabel2);

        jTextField1.setMinimumSize(new java.awt.Dimension(10, 25));
        jTextField1.setPreferredSize(new java.awt.Dimension(60, 25));
        jPanel1.add(jTextField1);

        jSpinner1.setModel(new javax.swing.SpinnerNumberModel());
        jSpinner1.setPreferredSize(new java.awt.Dimension(100, 25));
        jPanel1.add(jSpinner1);

        ok.setText("OK");
        ok.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okActionPerformed(evt);
            }
        });
        jPanel1.add(ok);

        cancel.setText("CANCEL");
        cancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelActionPerformed(evt);
            }
        });
        jPanel1.add(cancel);

        add(jPanel1, java.awt.BorderLayout.CENTER);

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Transfer");
        add(jLabel1, java.awt.BorderLayout.PAGE_START);
    }// </editor-fold>//GEN-END:initComponents

    private void okActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okActionPerformed
        JDialog dialog = new JDialog();
        EnterPin ep = new EnterPin(dialog);
        dialog.setTitle("Enter PIN");
        dialog.add(ep);
        dialog.setSize(200, 75);
        dialog.setModalityType(Dialog.ModalityType.TOOLKIT_MODAL);
        dialog.setLocationRelativeTo(atm);
        dialog.setVisible(true);
        
        
        String input = ep.getPIN().trim();
        
        
        if (atm.transfer(input, Double.parseDouble(jSpinner1.getValue().toString()),
                atm.getRootId(jTextField1.getText()))) {
            
            javax.swing.JOptionPane.showMessageDialog(current, "Transa"
                    + "ction complete!\n Remaining Balance: "
                    + atm.checkBalance());
        } else {
            javax.swing.JOptionPane.showMessageDialog(current, 
                    "Transfer Failed!");
        }
        current.dispose();
        atm.setVisible(true);
    }//GEN-LAST:event_okActionPerformed

    private void cancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelActionPerformed
        current.dispose();
        atm.setVisible(true);
    }//GEN-LAST:event_cancelActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton cancel;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JSpinner jSpinner1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JButton ok;
    // End of variables declaration//GEN-END:variables
}
